package jdo.crud;

import java.io.IOException;
import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jdo.entity.Tramway;
import jdo.pmf.PMF;

/**
 * Servlet implementation class ListServlet
 */
@SuppressWarnings("serial")
public class AddServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
			IOException {
		PersistenceManager pm = PMF.getPersistenceManager();
		String name = request.getParameter("name");
		Double coord_x = Double.parseDouble(request.getParameter("coord_x"));
		Double coord_y = Double.parseDouble(request.getParameter("coord_y"));
		// Create a record
		Tramway tramway = new Tramway(name,coord_x,coord_y);
		pm.makePersistent(tramway);
		pm.close();
		response.sendRedirect("/menu.jsp?message=createdOK");
	}

}
